// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

// 引入Element-UI库
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// 为了解决ie9和一些低版本的高级浏览器对es6新语法并不支持，添加下面的配置项
import "babel-polyfill"

// 引入iconfont样式
import './assets/icon/iconfont.css'
import { debug } from 'util';

// 添加Element-UI的配置
Vue.use(ElementUI)


Vue.config.productionTip = false


//引用LeanCloud
//初始化LeanCloud
//图南鸟
var APP_ID = '8J0hrsnXgeP4tjBrS7T4d1MR-gzGzoHsz';
var APP_KEY = '67vePTxUmsKH6YaHjtKRyic8';


//纤纸洁
// var APP_ID = 'xG5WxVnAqmwDCVO8AfunLjlo-gzGzoHsz';
// var APP_KEY = 'Gc98QTjlIQr5C4x2ie59cpTb';
var AV = require('leancloud-storage');

AV.init({ appId: APP_ID, appKey: APP_KEY });

//增加通用方法
Array.prototype.mycontains = function (obj) {
    // debugger;
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
  const role = localStorage.getItem('ms_username');
  //const shop_id = localStorage.getItem('shop_id')
//    console.log(shop_id)
//    debugger;
//   if(){
//     // next({path:'/login'});
//     router.push({path:'/login'})
//     next();
//   }
//   debugger;
    // console.log(to.path)

  if((!role ) && to.path!='/login'&& to.path!='/register'){
    next('/login?redirect='+to.fullPath)
  }
//   else if(){ //如果shop_id不存在
//     // next('/login');
//     //     router.push({path:'/login'})
//     // next();
//     next('/login?redirect='+to.fullPath)
//   }
 else if(to.meta.permission){
      // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
      role === 'Administrator' ? next() : next('/403');
  }else{
      // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
      if(navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor'){
          Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
              confirmButtonText: '确定'
          });
      }else{
          next();
      }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})